<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
 <%@page import="com.is.control.AttendanceTimeControl"%>
<%@page import="com.is.util.DateTime"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.CourseClass"%>
<%@page import="com.is.control.CourseClassControl"%>
<%@page import="com.is.util.ParamUtil"%>
<%@page import="com.is.control.UserControl"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.control.ParamClassControl"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<%@page import="com.is.model.ParamStuyear"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.model.ParamCourse"%>
<%@page import="com.is.model.ParamClass"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
	$(function(){
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top);
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				});
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				});
			}
		);
		var h = $(".right").height();
		$(".left").height(h);
		$(".update").click(function(){
			$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
		});
		$('img').error(function(){
			this.src = "/InterStu/resources/image/man.GIF";
		});
		/*更新*/
		$(".updataStatus").click(function(){
			artDialog.fn.shake = function (){
			    var style = this.DOM.wrap[0].style,
			        p = [4, 8, 4, 0, -4, -8, -4, 0],
			        fx = function () {
			            style.marginLeft = p.shift() + 'px';
			            if (p.length <= 0) {
			                style.marginLeft = 0;
			                clearInterval(timerId);
			            };
			        };
			    p = p.concat(p.concat(p));
			    timerId = setInterval(fx, 13);
			    return this;
			};
			var temUrl = $(this).attr("rel");
			var dialog = $.dialog({
		    content: '<p>本次操作权限为高级管理员。<br/>请输入口令，以进行操作！</p>'
		    	+ '<input id="demo-labs-input" style="width:15em; padding:4px" />',
		    fixed: true,
		    id: 'Fm7',
		    icon: 'question',
		    okVal: '回答',
		    ok: function () {
		    	var input = document.getElementById('demo-labs-input');
		        
		    	if (input.value !== '\u9884\u79d1') {
		            this.shake && this.shake();// 调用抖动接口
		            input.select();
		            input.focus();
		            return false;
		        } else {
		            window.location = "updateStatus.jsp?" + temUrl;
		        };
		    },
		    cancel: true
		});
		});
		/*公式*/
		var reg = /^\d*\.?\d*$/;
		$(".expression").bind("keyup keydown",function(e){
			var currentSum = 0;
			for(var i = 0,j=0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
					j++;
				}
			}
			if(j == 4 && currentSum !=100){
				var temVal = $(this).val();
				$(".expression").val("");
				$(this).val(temVal);
			}
			currentSum-=$(this).val()*1;
			if(!reg.test($(this).val()) || $(this).val()*1 + currentSum >100){
				var tem = $(this).val().substring(0,$(this).val().length-1);
				$(this).val(tem);
			}
			if(($(this).val()+"").length<2 && $(this).val()!= "" && $(this).val()*1 === 0 && e.keyCode!=8 || $(this).val()== "."){
				 $(this).val("0.");
			}
		})
		.blur(function(){
			if($(this).val() != "" && $(this).val()*1 == 0){
				$(this).val("0.0");
			}
			var sum = 0;
			var j = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					j++;
					sum += $(".expression").eq(i).val()*1;
				}
			}
			if(j>2){
				for(var i = 0;i<$(".expression").size();i++){
					if($(".expression").eq(i).val() == "")
					$(".expression").eq(i).val(100 - sum);
				}
			}
		});
		$(".reset").click(function(e){
			$(".expression").val("");
		});
		$("[name='add_gs']").submit(function(e){
			var currentSum = 0;
			for(var i = 0;i<$(".expression").size();i++){
				if($(".expression").eq(i).val() != ""){
					currentSum += $(".expression").eq(i).val()*1;
				}
			}
			if(currentSum != 100){
				e.preventDefault();
			}
		});
		/*numonly*/
		var numreg = /^\d+$/;
		$("[name='prevTotalClass']").bind("input",function(){
			if(!numreg.test($(this).val())){
				var tem = $(this).val().substring(0,$(this).val().length-1);
				$(this).val(tem);
			}
		});
		/*delete_course*/
		$("[name='delete_course']").click(function(){
			var $this = $(this);
			var cc_id = $this.parent().parent().find("[name='ccId']").val();
			var rel_course=$this.parent().parent().find(".rel_course").html();
			if(rel_course!=0){
				$.dialog({
					title:"删除提示",
					icon:"error",
					content:"对不起，您选择的老师已有实际课时</br>系统不能删除。</br>",
					okValue:"确定",
					ok:function(){}
				});
			} else{
				$.dialog.confirm("您确定要删除本次分配吗？",
				function(){
					$.ajax({
						type:"post",
						cache:false,
						url:"delete_action.jsp",
						data:{
							ccId:cc_id
						},
						success:function(data){
							if(data==1){
								$this.parent().parent().remove();
								var h = $(".right").height();
								$(".left").height(h);
								$.dialog.tips('删除操作已执行');
							} else{
								$.dialog.tips('本次操作异常');
							}
						}
					});
				},function(){
					$.dialog.tips('本次操作已取消');
				});
			}
		});
		
		/*update_course*/
		$("[name='update_course']").click(function(){
			var $this = $(this);
			var teacher_name=$this.parent().parent().find(".teacher_name").html();
			var pre_course=$this.parent().parent().find(".pre_course");
			var cc_id = $this.parent().parent().find("[name='ccId']").val();
			var dialog =$.dialog({
				content:"<table class='update'><tr><td>姓名</td><td>"+teacher_name
				+"</td></tr><tr><td>预计课时</td><td><input type='text' name='update_course' value="+pre_course.html()
				+"></td></tr><tr><td colspan='2'><input type=\"button\" name='update_submit' value='提交'/></td></tr></table>"
				
			});
			$("[name='update_submit']").click(function(){
				var update_course = $("[name='update_course']").val();
				$.ajax({
					type:"post",
					cache:false,
					url:"update_action.jsp",
					data:{
						ccId:cc_id,
						updateCourse:update_course
					},
					success:function(data){
						if(data == 1){
							dialog.close();
							pre_course.html(update_course);
							$.dialog.tips('修改操作已执行');
						} else{
							$.dialog.tips('本次操作异常');
						}
					}
				});
			});
		});
	});
</script>
<script type="text/javascript">
function change(){
			var selectYear = $("#stuyearId").val();
			$.ajax({
				type:"post",
				dataType:"html",
				url:"../students/printClass.jsp",
				data:{
					gradeYear:selectYear
				},
				cache:false,
				success:function(data){
					$("[name='selectClass']")[0].options.length = 0;
					$("[name='selectClass']").append("<option value='0'>全部</option>");
					$("[name='selectClass']").append(data);
				}
			});
}
  function checkedType(i){
  	  var obj = document.getElementsByName("searchType");
  	   obj[i].checked = true;
  }
</script>
<title>留学生预科班</title>
</head>
<%
     User cu =(User)session.getAttribute("user"); 
      //根据学期录入
      int cy = ParamStuyearControl.getCurrentStuyearId();
      int stuyear = ParamUtil.getInt(request,"stuyear",cy);//设置默认参数为当前学年
      int selectClass = ParamUtil.getInt(request, "selectClass",0);
      
        List<User> teas1 = UserControl.getAllUsersByRole("0");  //获取普通教师
		 List<User> teas2 = UserControl.getAllUsersByRole("1");  //获取管理员
		List<User> teas = new ArrayList<User>();
		teas.addAll(teas2);
		teas.addAll(teas1);
 %>
<body>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left"> 
	  <div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>" />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	   	  	
    	<div class="nav">
        	<ul>	 
            	</ul><br /><ul> 
                <li><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li> 
                <li class="active"><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li> 
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li> 
                <li><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li> 
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li> 
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class="r1">
    	<table class="user tab">
    <tr>
    	<td>
    		<a href="/InterStu/pages/users/user_all.jsp">添加用户</a>
		</td>
		<td>
			<a class="current" href="/InterStu/pages/courseClass/set.jsp">课程分配</a>
		</td>
    </tr>
    </table>
    	<form name="sxForm">
    	<table class='table'>
    	<caption>筛选条件</caption>
    		<tr>
				<td  rowspan="2">学期
				<select name="stuyear" id="stuyearId" onchange="change()">
					<%
					      List<ParamStuyear> pss = ParamStuyearControl.getAllStuyear();
					      for(ParamStuyear ps:pss){
					      %>
					      <option value="<%=ps.getId() %>" <%if(stuyear==ps.getId()) out.print("selected"); %>><%=ps.getStuyear()%></option>
					      <%
					      }
					 %></select>
				</td>
				<td  rowspan="2">
				<table class='table'><tr><td>
				<input type="radio" name="searchType" value="0">按班级
				<select name="selectClass" onchange="checkedType('0')">
				<option value='0'>全部</option>
					<%
					      List<ParamClass> pccs = ParamClassControl.getParamClassesByStuyear(cy);
					      for(ParamClass pc:pccs){
					      %>
					      <option value="<%=pc.getId() %>" <%if(selectClass==pc.getId()) out.print("selected"); %>><%=pc.getClassName()%></option>
					      <%
					      }
					 %></select>
				</td>
				<td><input type="submit" value="查看"/></td>
    		</tr>
    		<tr><td><input type="radio" name="searchType" value="1">按老师<select name="uid" onchange="checkedType('1')">
    		<option value="0">全部</option>
    			<%for(User tea:teas) {%>
			    		<option value="<%=tea.getId() %>"><%=tea.getName() %></option>
			   <%} %>
    		</select><td><input type="submit" value="查看"/></td></tr>
    		</table>
    		</td>
    	</table>
    	</form>
        </div>
        <div class="r2">
        <table class='table'>
        <caption>教师任课以及课时分配情况</caption>
	        <%
	        			int searchType=  ParamUtil.getInt(request, "searchType",0);
	        			int uid=  ParamUtil.getInt(request, "uid",0);
	        			List<CourseClass> ccs = new ArrayList<CourseClass>();
	        			if(searchType==0){
	        				if(selectClass==0){
	        					 ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(uid,stuyear);
	        				}else{
	        					ccs = CourseClassControl.getAllCourseClassIdByClassIdAndStuyear(selectClass, stuyear);
	        				}
	        				
				        }else{
				        	 ccs = CourseClassControl.getAllCourseClassIdByUidAndStuyear(uid,stuyear);
				        }
				         if(ccs.size()==0){
				        	 out.print("<tr><td>暂无</td></tr>");
				         }else{
			%>
			<thead>
			 <tr>
			 <th>教师姓名</th>
			 <th>课程</th>
			 <th>班级</th>
			 <th>预计课时</th>
			 <th>实际课时(截止到<%=DateTime.SimpleDate() %>)</th>
			 <th>状态</th>
			 <th>操作</th>
			 </tr>
			 </thead>
			 <tbody>
			 <%
               for(CourseClass cc:ccs){
               	%>
               	<tr>
               	<td class="teacher_name"><%=UserControl.getUserById(cc.getUid()).getName() %></td>
               	<td><%=ParamCourseControl.getCourseById(cc.getCourseId()).getCourseName() %><input type='hidden' name="ccId" value="<%=cc.getId() %>"/></td>
               	<td><%=ParamClassControl.getClassName(cc.getClassId()) %></td>
               	<td class="pre_course"><%=cc.getPrevTotalClass() %></td>
               	<td class="rel_course"><%=cc.getRealTotalClass() %>
               	<%//=AttendanceTimeControl.getCount(cc.getId(),stuyear,"","")%></td>
               	<td><a class="updataStatus" href="javascript:void(0);" rel="<%="courseClassId=" + cc.getId()+"&status=" + cc.getState() %>"><%out.print((cc.getState()==1)?"成绩提交、不能修改":"正常");%></a></td>
               	<td><a href="javascript:void(0);" name="update_course">修改</a> | <a href="javascript:void(0);" name="delete_course">删除</a></td>
               	</tr>
               	<%
               }
			 %>
			 </tbody>
		</table>
			 <%} %>
			 
			 <br/>
			<%if(stuyear==cy){ %>
			<form action="deal.jsp" name='add_gs' method="post">
			<table class='table'>
			<caption>分配本学期教师任课情况</caption>
			<tr><td>教师</td>
			<td>
			<select name="uid">
			<%
			    for(User tea:teas){
			%>
			<option value="<%=tea.getId() %>"><%=tea.getName() %></option>
			<%} %>
			</select>
			</td><td>课程</td><td><select name="courseId">
			<%
			       List<ParamCourse> pcs = ParamCourseControl.getAllCoursesByType(ParamStuyearControl.getCurrentStuyear().getTypeId()+"");
			       for(ParamCourse pc:pcs){
			 %>
			<option value="<%=pc.getId() %>"><%=pc.getCourseName() %></option>
			<%} %>
			</select></td>
			<td>班级</td>
			<td><select name="classId">
			<%
			       List<ParamClass> pcas = ParamClassControl.getParamClassesByStuyear(ParamStuyearControl.getCurrentStuyearId());
			       for(ParamClass pca:pcas){
			 %>
			<option value="<%=pca.getId() %>"><%=pca.getClassName() %></option>
			<%} %>
			</select></td>
			<td rowspan="2"><input type="submit" value="提交"/></td>
			</tr>
			<tr>
				<td>预计课时</td>
			<td><input style="width:80px;" type="text" name="prevTotalClass"/></td>
			<td>
				最终成绩分布
			</td>
			<td colspan="3">
				出勤：<input class="expression" style="width:30px" type="text" name="cq"/>&nbsp;%，
				平时：<input class="expression" style="width:30px" type="text" name="daily"/>&nbsp;%，
				期中：<input class="expression" style="width:30px" type="text" name="mid"/>&nbsp;%，
				期末：<input class="expression" style="width:30px" type="text" name="final"/>&nbsp;% 
				&nbsp;<a href="javascript:void(0);" class="reset">[清空]</a>&nbsp;（输入所占最终成绩的比例）
			</td>
			</tr>
			</table>
			<br/>
			<p>
			<input type="button" value="返回课程添加" onclick="window.location.href='../paramCourse/course.jsp'"/></p>
			</form>
			<%} %>
        </div>
    </div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>
